package cn.com.xxlibrary.service.impl;

import java.util.LinkedList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import cn.com.xxlibrary.dao.IImportDao;
import cn.com.xxlibrary.orm.BooksBean;
import cn.com.xxlibrary.service.IImportService;
import cn.com.xxlibrary.util.UtilTools;

@Service
@Repository("importService")
public class ImportServiceImpl implements IImportService {
	
	@Resource
	private IImportDao importDao;

	@Override
	public void importBooks(List<List> content) {
		List<BooksBean> books = new LinkedList<BooksBean>();
		BooksBean book = new BooksBean();
		for (List b : content) {
			book.setBookBarCode((String) b.get(1));
			book.setBookCollection((String) b.get(3));
			book.setBookCallNo((String) b.get(4));
			book.setBookName((String) b.get(5));
			book.setBookChargePerson((String) b.get(6));
			book.setBookPublishing((String) b.get(7));
			book.setBookPublishingTime((String) b.get(8));
			book.setBookPrice(Double.valueOf((String) b.get(9)));
			book.setISBN((String) b.get(10));
			book.setBookCount(1);
			book.setBookLoanCount(0);
			book.setBookStorageTime(UtilTools.receiveNowTime());
			book.setDataType(0);
			books.add(book);
			book = new BooksBean();
		}
		importDao.importBooks(books);
	}
	public void importDisks(List<List> content){
		List<BooksBean> books = new LinkedList<BooksBean>();
		BooksBean book = new BooksBean();
		for (List b : content) {
			book.setBookBarCode((String) b.get(1));
			book.setBookCollection((String) b.get(3));
			book.setBookCallNo((String) b.get(4));
			book.setBookName((String) b.get(5));
			book.setBookChargePerson((String) b.get(6));
			book.setBookPublishing((String) b.get(7));
			book.setBookPublishingTime((String) b.get(8));
			book.setBookPrice(Double.valueOf((String) b.get(9)));
			book.setISBN((String) b.get(10));
			book.setBookCount(1);
			book.setBookLoanCount(0);
			book.setBookStorageTime(UtilTools.receiveNowTime());
			book.setDataType(1);
			books.add(book);
			book = new BooksBean();
		}
		importDao.importBooks(books);
	}
	public void importPeriodicals(List<List> content){
		List<BooksBean> books = new LinkedList<BooksBean>();
		BooksBean book = new BooksBean();
		for (List b : content) {
			book.setPerPeriods((String) b.get(5));
			book.setPeriType((String) b.get(3));
			book.setPeriNo((String) b.get(1));
			book.setBookName((String) b.get(2));
			book.setBookPrice(Double.valueOf((String) b.get(4)));
			book.setBookCount(1);
			book.setBookLoanCount(0);
			book.setDataType(2);
			books.add(book);
			book = new BooksBean();
		}
		importDao.importBooks(books);

	}

}
